// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'
import flexbugs from 'postcss-flexbugs-fixes'
import autoprefixer from 'autoprefixer'
import pxtorem from 'postcss-pxtorem';
// import wasm from '@wasm-tool/wasm-pack-plugin';
// import path from 'path';


// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    VitePWA({
      registerType: 'autoUpdate',
      includeAssets: ['favicon.ico', 'robots.txt', 'icons/*.png'],
      manifest: {
        name: 'Xiong',
        short_name: 'Xiong',
        description: '',
        theme_color: '#1677ff',
        icons: [
          {
            src: 'icons/icon-192x192.png',
            sizes: '192x192',
            type: 'image/png'
          },
          {
            src: 'icons/icon-512x512.png',
            sizes: '512x512',
            type: 'image/png'
          }
        ]
      },
      workbox: {
        globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
      }
    })
  ],
  css: {
    postcss: {
      plugins: [
        flexbugs(),
        autoprefixer(),
        pxtorem({
          rootValue: 37.5, // 与 `px2rem` 的 remUnit 相同
          propList: ['*'] // 需要转换的属性，`*` 代表所有
        }),
        // wasm({
        //   crateDirectory: path.resolve(__dirname, 'src/pkg'), 
        // })
      ]
    }
  },
  resolve: {
    alias: {
      '@': '/src'
    },
    extensions: ['.js', '.jsx', '.ts', '.tsx']
  },
  server: {
    port: 3000,
    host: true
  }
})